﻿using System;
using System.Net;

namespace HttpCrawler.Engine
{
    public static class HttpCrawlerContentFactory
    {
        public static HttpCrawlerContent Create(Uri requestUrl, Uri referrerUrl, HttpWebResponse webResponse)
        {
            var mimeType = webResponse.GetMimeType();

            if (HttpCrawlerContent.IsHtml(mimeType))
            {
                return new HtmlHttpCrawlerContent(requestUrl, referrerUrl, webResponse);
            }
            else if (HttpCrawlerContent.IsXml(mimeType))
            {
                return new XmlHttpCrawlerContent(requestUrl, referrerUrl, webResponse);
            }

            return new HttpCrawlerContent(requestUrl, referrerUrl, webResponse);
        }
    }
}
